package idv.arthur.svn;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNPropertyValue;
import org.tmatesoft.svn.core.io.ISVNWorkspaceMediator;

public class CommitMediator implements ISVNWorkspaceMediator {


	private Map<Object, ByteArrayOutputStream> myTmpStorages = new HashMap<Object, ByteArrayOutputStream>();

	public SVNPropertyValue getWorkspaceProperty(String path, String name)
			throws SVNException {
		return null;
	}

	public void setWorkspaceProperty(String path, String name, String value)
			throws SVNException {
	}

	public OutputStream createTemporaryLocation(String path, Object id)
			throws IOException {
		ByteArrayOutputStream tempStorageOS = new ByteArrayOutputStream();
		myTmpStorages.put(id, tempStorageOS);
		return tempStorageOS;
	}

	public InputStream getTemporaryLocation(Object id) throws IOException {
		return new ByteArrayInputStream(
				((ByteArrayOutputStream) myTmpStorages.get(id))
						.toByteArray() );
	}

	public long getLength(Object id) throws IOException {
		ByteArrayOutputStream tempStorageOS = (ByteArrayOutputStream) myTmpStorages
				.get(id);
		if (tempStorageOS != null) {
			return tempStorageOS.size();
		}
		return 0;
	}

	public void deleteTemporaryLocation(Object id) {
		myTmpStorages.remove(id);
	}

	public void setWorkspaceProperty(String path, String name,
			SVNPropertyValue value) throws SVNException {
	}


}
